@extends('admin.main.layout')
@section('title', '短链接列表')
@section('content')
<div class="row">
    <div class="col-lg-12">
        <div class="card">
            <div class="card-body">
                <form class="m-search" method="GET" action="{{ URL::current(); }}">
                    <div class="m-search-items">
                        <div class="m-search-item">
                            <label>分组名称</label>
                            <select class="m-select" name="group_id">
                                @foreach($groupLists as $groupList)
                                <option value="{{ $groupList->group_id }}">{{ $groupList->name }}</option>
                                @endforeach
                            </select>
                        </div>
                        <div class="m-search-item">
                            <label>链接名称</label>
                            <input type="text" name="name" placeholder="请输入链接名称">
                        </div>
                        <div class="m-search-item">
                            <button type="submit" class="button">搜索</button>
                        </div>
                    </div>
                    <div class="m-search-handle">
                        <a class="button" href="/admin/short/short_add">
                            <i class="mdi mdi-plus-circle"></i>
                            <font>创建短链接</font>
                        </a>
                    </div>
                </form>
                <div>
                    <table class="table table-bordered">
                        <thead>
                            <tr>
                                <th>短链接ID</th>
                                <th>名称</th>
                                <th>到期时间</th>
                                <th>创建时间</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            @forelse($shortLists as $shortList)
                            <tr>
                                <td>{{ $shortList->short_id }}</td>
                                <td>{{ $shortList->name }}</td>
                                <td>{{ date("Y-m-d H:i:s",$shortList->deadline) }}</td>
                                <td>{{ $shortList->created_at }}</td>
                                <td>
                                    <div style="display:flex;flex-direction: row;">
                                        <a href="javascript:;" class="text-primary" onclick="copyShortLink('{{ $shortList->short_link }}');"  style="margin-right:5px;">复制短链</a> | 
                                        <a href="/admin/short/detial/{{ $shortList->short_id }}" style="margin:0 5px;">短链详情</a> | 
                                        <div class="dropdown" style="margin-left:5px;">
                                            <a href="javascript:;" data-toggle="dropdown" aria-expanded="false">更多 <span class="caret"></span></a>
                                            <ul class="dropdown-menu dropdown-menu-right">
                                                <li><a href="/admin/short/short_update/{{ $shortList->short_id }}">更新链接</a> </li>
                                                <li><a href="/admin/short/short_delete/{{ $shortList->short_id }}" class="text-danger">删除链接</a></li>
                                            </ul>
                                        </div>
                                    </div>
                                </td>
                            </tr>
                            @empty
                            <tr>
                                <td colspan="7">当前暂无链接</td>
                            </tr>
                            @endforelse
                        </tbody>
                    </table>
                </div>
                <div class="">
                    <ul class="pagination">
                        {!! $shortLists->appends($condition)->render() !!}
                    </ul>
                </div>
            </div>
        </div>
    </div>
</div>
<div id="copylink" data-clipboard-text="" name=""></div>
<script src="https://file.wailian1.cn/admin/js/public/clipboard.min.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
        var copylink = new ClipboardJS('#copylink');
        copylink.on('success', function(e) {
            mviewToastr("success","链接复制成功，请粘贴获取链接!");
        });
    });

    function copyShortLink(short_link) {
        $('#copylink').attr("data-clipboard-text",short_link);
        $("#copylink").trigger("click");
    }
</script>
@endsection
